package com.springBoot.springBootSysCore.modules.enums;

import com.springBoot.springBootSysCore.common.utils.enumUtils.EnumFindHelper;
import com.springBoot.springBootSysCore.common.utils.enumUtils.EnumKeyGetter;
import com.springBoot.springBootSysCore.common.utils.enumUtils.EnumKeyVal;

import java.util.List;
import java.util.Map;

/**
 * 支付方式
 * Created by timo on 2017/11/15.
 */
public enum PaymentWay{
    ALIPAY("支付宝","alipay"),
    WECHAT("微信","wechat"),
    BALANCE("银行卡","balance");

    private String name;
    private String val;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getVal() {
        return val;
    }

    public void setVal(String val) {
        this.val = val;
    }

    private PaymentWay(String name, String val) {
        this.name = name;
        this.val = val;
    }
    static final EnumFindHelper<PaymentWay, String> keyHelperT =
            new EnumFindHelper<PaymentWay, String>(PaymentWay.class, new KeyGetter());
    static final EnumFindHelper<PaymentWay, String> keyHelper =
                new EnumFindHelper<PaymentWay, String>(PaymentWay.class, new KeyGetter(), new ValGetter());

    static final EnumFindHelper<PaymentWay, String> valHelperT =
            new EnumFindHelper<PaymentWay, String>(PaymentWay.class,new ValGetter());
    static final EnumFindHelper<PaymentWay, String> valHelper =
                new EnumFindHelper<PaymentWay, String>(PaymentWay.class,new ValGetter(), new KeyGetter());

    static class KeyGetter implements EnumKeyGetter<PaymentWay, String> {
        @Override
        public String getKey(PaymentWay enumValue) {
            return enumValue.name;
        }
    }
    static class ValGetter implements EnumKeyGetter<PaymentWay, String> {
        @Override
        public String getKey(PaymentWay enumValue) {
            return enumValue.val;
        }
    }
   /* static class OrderKeyGetter implements EnumKeyGetter<PaymentWay, Integer> {
        @Override
        public Integer getKey(PaymentWay enumValue) {
            return enumValue.order;
        }
    }*/
    public static PaymentWay valfindT(String name, PaymentWay defaultValue){
        return keyHelperT.findT(name, defaultValue);
    }
    public static PaymentWay nameFindT(String val, PaymentWay defaultValue){
        return valHelperT.findT(val, defaultValue);
    }
    public static Object valfind(String name, String defaultValue){
        return keyHelper.find(name, defaultValue);
    }
    public static Object nameFind(String val, String defaultValue){
        return valHelper.find(val, defaultValue);
    }
    public static List<EnumKeyVal> keyValList(){
        return keyHelper.keyValList();
    }
}
